renderbackground: Avoid excess css value lookups
authorTimm Bäder <mail@baedert.org>
Tue, 9 Jan 2018 05:12:46 +0000 (06:12 +0100)
committerTimm Bäder <mail@baedert.org>
Wed, 10 Jan 2018 07:46:22 +0000 (08:46 +0100)
We iterate over all background layers twice, so only lookup blend mode
vlaues once.

gtk/gtkrenderbackground.c

index 57a07413b895e710ea03d8b1a03f1159cc607743..7957f97b208fedc2162e927a2945d0830b49feff 100644 (file)
@@ -623,9 +623,9 @@ gtk_css_style_snapshot_background (GtkCssStyle      *style,
   GtkCssValue *background_image;
   GtkCssValue *box_shadow;
   GtkCssValue *blend_modes;
-  GskBlendMode blend_mode;
   const GdkRGBA *bg_color;
   gint number_of_layers;
+  GskBlendMode *blend_mode_values;
 
   background_image = gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BACKGROUND_IMAGE);
   bg_color = _gtk_css_rgba_value_get_rgba (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BACKGROUND_COLOR));
@@ -646,13 +646,15 @@ gtk_css_style_snapshot_background (GtkCssStyle      *style,
 
   blend_modes = gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BACKGROUND_BLEND_MODE);
   number_of_layers = _gtk_css_array_value_get_n_values (background_image);
+  blend_mode_values = g_alloca (sizeof (GskBlendMode) * number_of_layers);
 
   for (idx = number_of_layers - 1; idx >= 0; idx--)
     {
-      blend_mode = _gtk_css_blend_mode_value_get (_gtk_css_array_value_get_nth (blend_modes, idx));
+      blend_mode_values[idx] = _gtk_css_blend_mode_value_get (_gtk_css_array_value_get_nth (blend_modes, idx));
 
-      if (blend_mode != GSK_BLEND_MODE_DEFAULT)
-        gtk_snapshot_push_blend (snapshot, blend_mode, "Background<%u>Blend<%u>", idx, blend_mode);
+      if (blend_mode_values[idx] != GSK_BLEND_MODE_DEFAULT)
+        gtk_snapshot_push_blend (snapshot, blend_mode_values[idx], "Background<%u>Blend<%u>",
+                                 idx, blend_mode_values[idx]);
     }
 
   if (!gdk_rgba_is_clear (bg_color))
@@ -660,9 +662,7 @@ gtk_css_style_snapshot_background (GtkCssStyle      *style,
 
   for (idx = number_of_layers - 1; idx >= 0; idx--)
     {
-      blend_mode = _gtk_css_blend_mode_value_get (_gtk_css_array_value_get_nth (blend_modes, idx));
-
-      if (blend_mode == GSK_BLEND_MODE_DEFAULT)
+      if (blend_mode_values[idx] == GSK_BLEND_MODE_DEFAULT)
         {
           gtk_theming_background_snapshot_layer (&bg, idx, snapshot);
         }